package redis

import (
	"context"
	"github.com/redis/go-redis/v9"
)

var (
	rdb *redis.Client
)

type RedisDao interface {
	Get(key string) (string, error)
}

type RedisDaoImpl struct {
	client *redis.Client
}

func NewRedisDaoImpl(addr string, password string) *RedisDaoImpl {
	client := redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: password, // no password set
		DB:       0,        // use default DB
	})
	return &RedisDaoImpl{
		client: client,
	}
}
func (r *RedisDaoImpl) Get(key string) (string, error) {
	return r.client.Get(context.Background(), key).Result()
}

func (r *RedisDaoImpl) Set(key string, value string) error {
	return r.client.Set(context.Background(), key, value, 0).Err()
}
